<?php
	
/**
 * 红包
 */
if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');
global $_GPC,$_W;
$rid= intval($_GPC['rid']);
if(empty($rid)){
    message('抱歉，传递的参数错误！','', 'error');              
}

  $params = array(':rid' => $rid);
  $list = pdo_fetchall("SELECT * FROM " . tablename('redpacksend_rp_prize') . " WHERE activityId = :rid   ORDER BY id asc ", $params);
  foreach ($list as &$row) {
	if($row['status'] == 0){
		$row['status']='未激活';
	}elseif($row['status'] == 1){
		$row['status']='已激活';
	}elseif($row['status'] == 2){
		$row['status']='已发出';
	}else{
        $row['status']='出错';
    }
}


$tableheader = array('ID', '密钥','金额','用户','发出时间', '状态' ,'活动编号');
$html = "\xEF\xBB\xBF";
$html .= implode("\t,",$tableheader);
$html .= "\r\n";
foreach ($list as $value) {
    $html .= $value['id'] . "\t ,";
    $html .= $value['password'] . "\t ,";
    $html .= $value['money'] . "\t ,";
    $html .= $value['openid'] . "\t ,";
    $html .= date('Y-m-d H:i:s', $value['receiveTime'])  . "\t ,";
    $html .= $value['status'] . "\t ,";
    $html .= $value['activityId'] . "\r\n";
}

header("Content-type:text/csv");
header("Content-Disposition:attachment; filename=红包记录.csv");

echo $html;
exit();
